public class ConstructArray {

    public int[] constructArray(int n, int k) {
        int[] ans = new int[n];
        for (int i = k + 1; i < n; i++) {
            ans[i] = i + 1;
        }
        int l = 1;
        int r = k + 1;
        for (int i = 0; i < k + 1; i++) {
            if (i % 2 == 0) {
                ans[i] = l;
                ++l;
            } else {
                ans[i] = r;
                --r;
            }
        }
        return ans;
    }
}
